package com.xcity.game.equip.suit4.impl;

import com.xcity.game.combat.Action;
import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.Combat;
import com.xcity.game.combat.attr.CombatAttributeType;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.equip.suit4.BaseSuit4;
import com.xcity.game.equip.template.EquipSuitEffectTemplate;

/**
 * 登喜路4件套<br/>
 * 生命值低于{10}%时{100}%反弹下一次攻击的全部伤害
 * @author yang.li
 *
 */
public class Suit4Dunhill extends BaseSuit4 {

	private boolean rebound;
	
	public Suit4Dunhill(CombatUnit unit, EquipSuitEffectTemplate template) {
		super(unit, template);
	}

	@Override
	public void afterDamage(ActionEffect effect) {
		if (unit.getId() != effect.getUnitId()) {
			return;
		}
		if (rebound) {
			if (!unit.isDied()
					&& effect.getHpDelta() < 0
					&& Combat.RND.nextInt(GameStaticConfig.percentBase) < template.getSuit4Param(1)) {
				Action newAct = new Action(unit);
				effect.ref().ref().add(newAct);
				ActionEffect eff = newAct.addTarget(effect.ref().unit);
				int hpDelta = effect.getHpDelta();
				eff.effect(CombatAttributeType.HP, hpDelta);
			}
		} else if (unit.getHp() < unit.getMaxHp() * template.getSuit4Param(0) / GameStaticConfig.percentBase) {
			rebound = true; // 标记下一次受到伤害时反弹
		}
	}

}
